Skip to content

Clean up interrupted JavaScript dependency downloads - #387

Draft
BenCodez wants to merge 1 commit into
masterfrom
fix/javascript-download-cleanup
Draft

BenCodez wants to merge 1 commit into
masterfrom
fix/javascript-download-cleanup

Conversation

@BenCodez

@BenCodez BenCodez commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

An interrupted optional JavaScript dependency download could leave its partial temporary file behind. Give each attempt a unique sibling candidate and remove only that candidate when transfer or publication fails, preserving other attempts and any existing target.

Close streams and disconnect on failure paths. Preserve the original exception and attach cleanup failures as suppressed exceptions. A detected thread interruption before replacement prevents publishing that candidate without clearing the interrupt flag. Successful nonempty transfers retain the existing replacement behavior. This does not add a stale-file purge policy or change dependency selection.

Validation on exact commit c93b5d1: deterministic baseline-failing interrupted-transfer regression; 35 focused JavaScript tests; clean JDK 21 package with 1,730 ordinary tests and two artifact checks, zero failures/errors. Seven new component tests cover interruption, competing attempts, resource failures, empty downloads, replacement failure, cleanup failure and retry. Independent source review approved the exact snapshot and independently passed 52 focused tests, including all seven download tests.

Tests use synthetic in-memory connections and temporary files. No live download, server, script-engine or native runtime acceptance is claimed.

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of JavaScript dependency downloads. Interrupted, cancelled, failed, or empty transfers no longer leave partial artifacts in place or overwrite a previously available file.
    • Temporary download files are cleaned up after failures, and existing artifacts remain intact when a replacement cannot be completed. Connections are also closed when downloads finish or fail.

@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

downloadArtifact now downloads to a temporary candidate file, checks for empty or interrupted transfers, and moves the completed file into place. It cleans up the candidate after failures. A new test suite covers transfer failures, cleanup, publication, stream closure, and connection disconnection.

Changes: Artifact download

Layer / File(s) Summary
Download publication and failure handling
AdvancedCore/src/main/java/com/bencodez/advancedcore/api/javascript/JavascriptEngineHandler.java, AdvancedCore/src/test/java/com/bencodez/advancedcore/tests/javascript/JavascriptDependencyDownloadTest.java
downloadArtifact stages downloads in a temporary candidate file, rejects empty or interrupted transfers, and moves completed candidates into place. On failure, it attempts candidate cleanup and suppresses cleanup failures on the original exception. Tests cover failure cases, existing-file preservation, successful publication, stream closure, and connection disconnection.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Merge Risk: Minimal · up to c93b5

Optional JavaScript dependency downloads now use a unique temporary file per attempt and remove it if the transfer fails or is interrupted. Existing files are preserved and successful downloads still replace them. No actionable merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Clean up interrupted JavaScript dependency downloads" matches the main change. The PR changes JavascriptEngineHandler.downloadArtifact so each download attempt uses a unique temporary candi…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Clean up interrupted JavaScript dependency downloads" matches the main change. The PR changes JavascriptEngineHandler.downloadArtifact so each download attempt uses a unique temporary candidate file. On failure, interruption, or empty download, the code deletes only that candidate and attaches cleanup failures as suppressed exceptions. A new JUnit test class covers these cases. The title names the primary behavior and does not list files.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 405b3669-3fbd-4eaa-8150-9456333e7e2a
Commits

Reviewing files that changed from the base of the PR and between 5d14329 and c93b5d1.

Files selected for processing: 2

  • AdvancedCore/src/main/java/com/bencodez/advancedcore/api/javascript/JavascriptEngineHandler.java
  • AdvancedCore/src/test/java/com/bencodez/advancedcore/tests/javascript/JavascriptDependencyDownloadTest.java

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Recent review details

Context from checks skipped due to timeout: 3

  • GitHub Check: build
  • GitHub Check: Analyze (java-kotlin)
  • GitHub Check: Analyze (actions)
Additional context used

Code guidelines: 1

AGENTS.md — auto-discovered
Path-based instructions: 2

Source excerpt: AdvancedCore is a shared Bukkit/Paper/Folia library embedded by plugins such as VotingPlugin, MCPerks, and GraveStonesPlus.

CodeRabbit inference engine (AGENTS.md)

Files:

  • AdvancedCore/src/main/java/com/bencodez/advancedcore/api/javascript/JavascriptEngineHandler.java
  • AdvancedCore/src/test/java/com/bencodez/advancedcore/tests/javascript/JavascriptDependencyDownloadTest.java
Source excerpt: All test classes and test-only helpers must live under `com.bencodez.advancedcore.tests` or its subpackages, with matching directories under `AdvancedCore/src/test/java`.

CodeRabbit inference engine (AGENTS.md)

Files:

  • AdvancedCore/src/test/java/com/bencodez/advancedcore/tests/javascript/JavascriptDependencyDownloadTest.java
Learnings: 1

Learning: 2026-11-16T20:27:41.191Z

Learnt from: CR
Repo: BenCodez/AdvancedCore PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-11-16T20:27:41.191Z
Learning: Applies to AdvancedCore/src/test/java/** : Source excerpt:
# Maintainer and AI-agent guide

## Build and verification

All test classes and test-only helpers must live under `com.bencodez.advancedcore.tests` or its subpackages, with matching directories under `AdvancedCore/src/test/java`. Keep tests out of production packages. Preserve production visibility when relocating tests; use narrowly scoped test-only reflective helpers when package-private access is required. Preserve test discovery and the package-phase artifact tests.

Applied to files:

  • AdvancedCore/src/test/java/com/bencodez/advancedcore/tests/javascript/JavascriptDependencyDownloadTest.java
ast-grep (0.51.1)

AdvancedCore/src/main/java/com/bencodez/advancedcore/api/javascript/JavascriptEngineHandler.java

[warning] 466-466: Temporary file not deleted
Context: Files.createTempFile(target.toAbsolutePath().getParent(), "download-", ".tmp")
Note: [CWE-377] Insecure Temporary File. Security best practice.

(tempfile-delete)

AdvancedCore/src/test/java/com/bencodez/advancedcore/tests/javascript/JavascriptDependencyDownloadTest.java

[warning] 239-239: Avoid user-generated class names for reflection
Context: Class.forName(JavascriptEngineHandler.class.getName() + "$MavenArtifact")
Note: [CWE-470] Use of Externally-Controlled Input to Select Classes or Code ('Unsafe Reflection').

(unsafe-reflection-java)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants